//
//  NSBundle+LLDigitTextChanger.m
//  live.ly
//
//  Created by bob on 16/6/20.
//  Copyright © 2016年 musical.ly. All rights reserved.
//

#import "NSBundle+LLDigitTextChanger.h"
#import <objc/runtime.h>


@interface LLDigitTextChangerBundleEx : NSBundle

@end


@implementation LLDigitTextChangerBundleEx

- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
{
    NSDictionary *dict = @{
        @"BUTTON_CREATE_ACCOUNT" : NSLocalizedString(@"Verify", nil),
        @"BUTTON_CREATING_ACCOUNT" : NSLocalizedString(@"Verifying", nil),
        @"BUTTON_CREATED_ACCOUNT" : NSLocalizedString(@"Verified", nil),
        @"BUTTON_LOGGING_IN" : NSLocalizedString(@"Verifying", nil),
    };
    if (dict[key]) {
        return dict[key];
    }
    if ([key isEqualToString:@"FOOTNOTE_CREATE_ACCOUNT"]) {
        NSString *originalWhole = [super localizedStringForKey:key value:value table:tableName];
        NSString *originalCreate = [super localizedStringForKey:@"BUTTON_CREATE_ACCOUNT" value:value table:tableName];
        NSString *str = [originalWhole stringByReplacingOccurrencesOfString:originalCreate withString:dict[@"BUTTON_CREATE_ACCOUNT"]];
        return str;
    }
    return [super localizedStringForKey:key value:value table:tableName];
}

@end


@implementation NSBundle (LLDigitTextChanger)

+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        static NSBundle *digitResourceBundle;
        digitResourceBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"DigitsKitResources" ofType:@"bundle"]];
        object_setClass(digitResourceBundle, [LLDigitTextChangerBundleEx class]);
    });
}

@end
